package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.UmsRoleMapper;
import com.mail.model.db.UmsRole;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/21 17:06
 **/
@DubboService
public class UmsRoleApiImpl implements UmsRoleApi{

	@Autowired
	private UmsRoleMapper umsRoleMapper;

	/**
	 * 根据 id 批量查询
	 *
	 * @param roleIds
	 * @return
	 */
	@Override
	public List<UmsRole> getByIds(List<Long> roleIds) {
		return umsRoleMapper.selectBatchIds(roleIds);
	}

	/**
	 * 获取所有角色信息
	 *
	 * @return
	 */
	@Override
	public List<UmsRole> getAll() {
		return umsRoleMapper.selectAll();
	}

	/**
	 * 根据角色名称分页获取角色列表(分页查询)
	 *
	 * @param pageNum
	 * @param pageSize
	 * @param keyword
	 * @return
	 */
	@Override
	public Page<UmsRole> getListByPage(Long pageNum, Long pageSize, String keyword) {
		Page<UmsRole> page = new Page<>(pageNum, pageSize);
		LambdaQueryWrapper<UmsRole> wrapper = new LambdaQueryWrapper<>();
		wrapper.like(StringUtils.isNotEmpty(keyword), UmsRole::getName, keyword);
		return umsRoleMapper.selectPage(page, wrapper);
	}

	/**
	 * 添加角色
	 *
	 * @param umsRole
	 */
	@Override
	public Integer create(UmsRole umsRole) {
		Integer count = umsRoleMapper.insert(umsRole);
		return count;
	}

	/**
	 * 批量删除角色
	 *
	 * @param ids
	 * @return
	 */
	@Override
	public Integer deleteByIds(List<Long> ids) {
		return umsRoleMapper.deleteBatchIds(ids);
	}

	/**
	 * 修改角色
	 *
	 * @param umsRole
	 * @return
	 */
	@Override
	public Integer update(UmsRole umsRole) {
		return umsRoleMapper.updateById(umsRole);
	}

	/**
	 * 根据id修改角色状态
	 *
	 * @param id
	 * @param status
	 */
	@Override
	public void updateStatus(Long id, Long status) {
		umsRoleMapper.updateStatus(id, status);
	}
}
